const Router = require('koa-router');
const router = new Router();

async function fetchData() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      Math.random() > 0.5 ? resolve('Hello from async data') : reject(new Error('Fetch failed'));
    }, 500);
  });
}

router.get('/', async (ctx) => {
  const data = await fetchData();
  ctx.body = { data };
});

module.exports = router;